package com.neusoft.tools;

import com.neusoft.nep.entity.AirQualityLevel;
import com.neusoft.nep.entity.nepsFeedback;
import javafx.geometry.Insets;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;


public class AlertUtils {
    /**
     * 展示一个弹窗
     *
     * @param title 弹窗的名称
     * @param contentText 弹窗内容
     */
    public static void showDialog(String title, String contentText){
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setTitle(title);
        alert.setHeaderText(null);
        alert.setContentText(contentText);
        alert.showAndWait();
    }
    /**
     * 显示一个包含空气质量等级详细信息的对话框
     * 公众监督员端用到的详情对话框
     * @param level 要显示详情的 AirQualityLevel 对象
     */
    public static void showAirQualityDetails(AirQualityLevel level) {
        Dialog<Void> dialog = new Dialog<>();
        dialog.setTitle("空气质量详情");
        dialog.setHeaderText("级别 " + level.getLevelId() + ": " + level.getLevelName());

        DialogPane dialogPane = dialog.getDialogPane();
        dialogPane.getButtonTypes().add(ButtonType.CLOSE);

        GridPane grid = new GridPane();
        grid.setHgap(10);
        grid.setVgap(10);
        grid.setPadding(new Insets(20, 20, 10, 10));

        grid.add(new Label("级别:"), 0, 0);
        grid.add(new Label(level.getLevelId()), 1, 0);

        grid.add(new Label("污染等级:"), 0, 1);
        grid.add(new Label(level.getLevelName()), 1, 1);

        Label descriptionLabel = new Label("对健康影响情况:");
        Text descriptionText = new Text(level.getDescription());
        descriptionText.setWrappingWidth(350);
        grid.add(descriptionLabel, 0, 2);
        grid.add(descriptionText, 1, 2);
        Label measuresLabel = new Label("建议采取的措施:");
        Text measuresText = new Text(level.getSuggestedMeasures());
        measuresText.setWrappingWidth(350);

        grid.add(measuresLabel, 0, 3);
        grid.add(measuresText, 1, 3);

        dialogPane.setContent(grid);
        dialog.showAndWait();
    }

    /**
     * 公众监督员端展示反馈的详情
     * @param entry 一条反馈
     */
    public static void showFeedbackDetails(nepsFeedback entry) {
        Dialog<Void> dialog = new Dialog<>();
        dialog.setTitle("反馈日志详情");
        dialog.setHeaderText("反馈记录");

        DialogPane dialogPane = dialog.getDialogPane();
        dialogPane.getButtonTypes().add(ButtonType.CLOSE);

        GridPane grid = new GridPane();
        grid.setHgap(10);
        grid.setVgap(12);
        grid.setPadding(new Insets(20, 20, 10, 10));

        Label nameLabel = new Label("姓名:");
        nameLabel.setFont(Font.font("System", FontWeight.BOLD, 12));
        grid.add(nameLabel, 0, 0);
        grid.add(new Text(entry.getUsername()), 1, 0);

        Label phoneLabel = new Label("手机号:");
        phoneLabel.setFont(Font.font("System", FontWeight.BOLD, 12));
        grid.add(phoneLabel, 0, 1);
        grid.add(new Text(entry.getPhoneNumber()), 1, 1);

        Label dateLabel = new Label("反馈日期:");
        dateLabel.setFont(Font.font("System", FontWeight.BOLD, 12));
        grid.add(dateLabel, 0, 2);
        grid.add(new Text(entry.getDate()), 1, 2);

        Label locationLabel = new Label("反馈地点:");
        locationLabel.setFont(Font.font("System", FontWeight.BOLD, 12));
        grid.add(locationLabel, 0, 3);

        grid.add(new Text(entry.getProvince() + " " + entry.getCity() + " " + entry.getAddress()), 1, 3);

        Label levelLabel = new Label("预估AQI等级:");
        levelLabel.setFont(Font.font("System", FontWeight.BOLD, 12));
        grid.add(levelLabel, 0, 4);
        grid.add(new Text(entry.getLevel()), 1, 4);

        Label contentLabel = new Label("详细内容:");
        contentLabel.setFont(Font.font("System", FontWeight.BOLD, 12));
        grid.add(contentLabel, 0, 5);

        Text contentText = new Text(entry.getContent());
        contentText.setWrappingWidth(350);
        grid.add(contentText, 1, 5);

        dialogPane.setContent(grid);
        dialog.showAndWait();
    }
}
